{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Shtgsp"

// By ArtemQa146

const
    Render_S = 31@
    Render_R = 30@
    Render_O = 29@
    Clip_Model = 27@
    Clip_X = 26@
    Clip_Y = 25@
    Clip_Z = 24@
    Render_R2 = 23@
    addgunshell = 22@
    Weapon_ID = 27
end

0085: Render_S = 0@ // (int)
0085: Render_R = 1@ // (int)
0085: Render_O = 2@ // (int)
0085: Clip_X = 3@ // (int)
0085: Clip_Y = 4@ // (int)
0085: Clip_Z = 5@ // (int)

        gosub @Visible_Weapon

            repeat
            wait 0
            if and
                not actor.Driving($PLAYER_ACTOR)
                02D8:   actor $PLAYER_ACTOR current_weapon == Weapon_ID
            then
                0A8D: 1@ = read_memory 0xB7CDD0 size 4 virtual_protect 0
                08C3: clear 1@ bit 12
                0A8C: write_memory 0xB7CDD0 size 4 value 1@ virtual_protect 0
                0A8C: write_memory 0x740CF0 size 4 value 0.0 virtual_protect 0 //0.30000001
                0A8C: write_memory 0x740CF8 size 4 value 0.0 virtual_protect 0 //0.44999999
                0E35: set_render_object_position Render_O 0 0 0
                0E35: set_render_object_position Render_R 0 0 0

                if or
                    Actor.Animation($PLAYER_ACTOR) == "buddy_fire"
                    Actor.Animation($PLAYER_ACTOR) == "buddy_fire_poor"
                    Actor.Animation($PLAYER_ACTOR) == "buddy_crouchfire"
                then
                    if Actor.Animation($PLAYER_ACTOR) == "buddy_fire"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "buddy_fire" time
                    end
                    if Actor.Animation($PLAYER_ACTOR) == "buddy_fire_poor"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "buddy_fire_poor" time
                    end
                    if Actor.Animation($PLAYER_ACTOR) == "buddy_crouchfire"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "buddy_crouchfire" time
                    end
                        if
                            1@ <= 0.4
                        then
                            if
                                1@ >= 0.3
                            then
                                2@ = 0.295
                                0087: 4@ = 1@ // (float)
                                0063: 4@ -= 2@  // (float)
                                4@ *= -1.0

                                2@ = 0.2990
                                0087: 5@ = 1@ // (float)
                                0063: 5@ -= 2@  // (float)
                                //5@ /= 2.0
                                5@ /= 5.0

                                2@ = 0.2995
                                0087: 6@ = 1@ // (float)
                                0063: 6@ -= 2@  // (float)
                                //6@ /= 2.0
                                6@ /= 4.0
                                6@ *= -1.0
                                if
                                    1@ <= 0.35
                                then
                                    0E35: set_render_object_position Render_O 4@ 5@ 6@
                                    0087: 14@ = 4@ // (float)
                                    0087: 15@ = 5@ // (float)
                                    0087: 16@ = 6@ // (float)
                                    addgunshell = 0
                                else
                                    if
                                        1@ <= 0.45
                                    then
                                        0E35: set_render_object_position Render_O 14@ 15@ 16@
                                    end
                                    if and
                                        1@ <= 0.45
                                        addgunshell == 0
                                    then
                                        0A96: 6@ = ped $PLAYER_ACTOR struct
                                        0D4E: 7@ = struct 6@ offset 0x718 size 1 //active weap slot
                                        6@ += 0x5A0
                                        7@ *= 0x1C
                                        005A: 6@ += 7@ //CWeapon
                                        0172: 4@ = actor $PLAYER_ACTOR Z_angle
                                        2@ = 0.0
                                        3@ = 0.0
                                        if or
                                            4@ > 315.0
                                            4@ < 45.0
                                        then
                                            2@ = 0.5
                                        else
                                            if and
                                                4@ > 135.0
                                                4@ < 225.0
                                            then
                                                2@ = -0.5
                                            else
                                                if and
                                                    4@ > 225.0
                                                    4@ < 315.0
                                                then
                                                    3@ = -0.5
                                                else
                                                    if and
                                                        4@ > 45.0
                                                        4@ < 135.0
                                                    then
                                                        3@ = 0.5
                                                    end
                                                end
                                            end
                                        end
                                        0D0B: get_actor $PLAYER_ACTOR bone 24 matrix_pointer_to 4@ // IF and SET
                                        0D0A: store_coords_to 10@ 11@ 12@ from_matrix 4@ with_offsets 0.184 0.016 0.096
                                        0A96: 20@ = ped $PLAYER_ACTOR struct
                                        0AA6: call_method 0x73A3E0 struct 6@ num_params 4 pop 0 0.30000001 2@v 10@v 20@
                                        //0x73A3E0 void __thiscall CWeapon::AddGunshell(CWeapon *this, CEntity *entity, CVector *position, CVector2D *direction, float size)
                                        addgunshell = 1
                                    end
                                end
                            end
                        end
                    end

                    get_char_weapon_clip $PLAYER_ACTOR store_to 0@
                    if and
                        0@ > 0
                        not Actor.Animation($PLAYER_ACTOR) == "buddy_reload"
                        not Actor.Animation($PLAYER_ACTOR) == "buddy_crouchreload"
                    then
                        10@ = 0
                    end

                        if or
                            Actor.Animation($PLAYER_ACTOR) == "buddy_reload"
                            Actor.Animation($PLAYER_ACTOR) == "buddy_crouchreload"
                        then
                            if Actor.Animation($PLAYER_ACTOR) == "buddy_reload"
                            then 0613: 1@ = actor $PLAYER_ACTOR animation "buddy_reload" time
                            end
                            if Actor.Animation($PLAYER_ACTOR) == "buddy_crouchreload"
                            then 0613: 1@ = actor $PLAYER_ACTOR animation "buddy_crouchreload" time
                            end
                                    if and
                                        1@ >= 0.5
                                        1@ <= 0.75
                                    then

                                            2@ = 0.495
                                            0087: 4@ = 1@ // (float)
                                            0063: 4@ -= 2@  // (float)
                                            4@ *= -1.0

                                            2@ = 0.4990
                                            0087: 5@ = 1@ // (float)
                                            0063: 5@ -= 2@  // (float)
                                            5@ /= 6.5


                                            2@ = 0.4995
                                            0087: 6@ = 1@ // (float)
                                            0063: 6@ -= 2@  // (float)
                                            //6@ /= 4.0
                                            6@ /= 3.7
                                            6@ *= -1.0
                                            
                                            if
                                                1@ <= 0.55
                                            then
                                                0E35: set_render_object_position Render_R 4@ 5@ 6@
                                                0087: 8@ = 4@ // (float)
                                                0087: 9@ = 5@ // (float)
                                                0087: 11@ = 6@ // (float)
                                            else
                                                0E35: set_render_object_position Render_R 8@ 9@ 11@
                                                if
                                                    1@ >= 0.65
                                                then
                                                    0087: 4@ = 1@ // (float)
                                                    4@ /= 200.0
                                                    005B: 8@ += 4@  // (float)
                                                    4@ /= 5.0
                                                    005B: 11@ += 4@  // (float)
                                                    4@ /= 2.0
                                                    0063: 9@ -= 4@  // (float)
                                                    if 8@ >= 0.0
                                                    then 8@ = 0.0
                                                    end
                                                    if 9@ <= 0.0
                                                    then 9@ = 0.0
                                                    end
                                                    if 11@ >= 0.0
                                                    then 11@ = 0.0
                                                    end
                                                end
                                            end
                                        end
                                    end


            else
                break
            end
            until not player.Defined(0)
                0A8D: 1@ = read_memory 0xB7CDD0 size 4 virtual_protect 0
                08BD: set 1@ bit 12
                0A8C: write_memory 0xB7CDD0 size 4 value 1@ virtual_protect 0
                0A8C: write_memory 0x740CF0 size 4 value 0.30000001 virtual_protect 0 //0.30000001
                0A8C: write_memory 0x740CF8 size 4 value 0.44999999 virtual_protect 0 //0.44999999
            gosub @Hide_Weapon

0A93: terminate_this_custom_script


:Hide_Weapon
0E31: set_render_object_visible Render_S 0
0E31: set_render_object_visible Render_R 0
0E31: set_render_object_visible Render_O 0
return

:Visible_Weapon
0E31: set_render_object_visible Render_S 1
0E31: set_render_object_visible Render_R 1
0E31: set_render_object_visible Render_O 1
return
